package it.das;

import it.das.service.BusinessModuleServices;


/**
 * "App" is composed of set of services!
 * @author ad
 * App is a demo application which was created to demonstrate the power of Aspect Oriented programming.
 * 
 */
public class App implements AppServices{
	/**
	 * Default entry.. to TEST
	 * PASS service name X Y
	 * @param args
	 */
    public static void main( String[] args ) {
    	if(args == null || args.length == 0){
    		System.err.println("nothing to do..pass X or Y ");
    	}else {
    		try{
	    		for(String arg : args){
	    			if(arg.equalsIgnoreCase("X")){
	    				doServiceX(null);
	    			}else if(arg.equalsIgnoreCase("Y")){
	    				doServiceY(null);
	    			}
	    		}
    		}catch (Exception e){
    			System.err.println(e.toString());
    		}
    	}
    }
    
    
    
    private static void doServiceX (Object input) throws Exception{
    	BusinessModuleServices service = new BusinessModuleServices();
    	service.doServiceX(input);
    }
    
    private static void doServiceY (Object input) throws Exception{
    	BusinessModuleServices service = new BusinessModuleServices();
    	service.doServiceY(input);
    }



	@Override
	public Object doService(Object... args) {
		Object ret = null;
		try{
			for(Object arg : args){
				if(arg.equals("X")){
					doServiceX(null);
				}else if(arg.equals("Y")){
					doServiceY(null);
				}else {
					ret = "nothing to do.. valid invocation [someObject].doService({X, Y .. }, args1, arg2, ..) ";
				}
			}
		}catch(Exception e){
			ret = e.toString();
		}
		return ret;
	}
}
